package com.itheima.project.vo.search;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mrchen
 * @date 2022/3/27 19:43
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SortParam {
    public static final String DESC = "desc";
    public static final String ASC = "asc";
    /**
     * 排序字段
     */
    private List<String> name = new ArrayList<>();
    /**
     * 升序或降序
     */
    private List<String> sort = new ArrayList<>();

    public static SortParam of(String field){
        SortParam sortParam = new SortParam();
        return sortParam.sortAsc(field);
    }
    public static SortParam of(){
        SortParam sortParam = new SortParam();
        return sortParam;
    }
    public SortParam sortDesc(String name){
        this.name.add(name);
        this.sort.add(DESC);
        return this;
    }
    public SortParam sortAsc(String name){
        this.name.add(name);
        this.sort.add(ASC);
        return this;
    }
}
